package com.example.plumneedle.PanelView;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.Html;
import android.text.InputType;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.plumneedle.Framgment.BlankFragment5;
import com.example.plumneedle.R;
import com.example.plumneedle.method.BasisTimesUtils;
import com.lljjcoder.Interface.OnCityItemClickListener;
import com.lljjcoder.bean.CityBean;
import com.lljjcoder.bean.DistrictBean;
import com.lljjcoder.bean.ProvinceBean;
import com.lljjcoder.style.cityjd.JDCityConfig;
import com.lljjcoder.style.cityjd.JDCityPicker;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;
import com.wildma.pictureselector.PictureBean;
import com.wildma.pictureselector.PictureSelector;

public class setup extends AppCompatActivity {
    private TextView textView1;
    private TextView textView2;
    private TextView textView;
    private TextView textView3;
    private ImageView imageView;
    private ImageView imageButton;
    private static PictureBean pictureBean;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup);
        textView1=findViewById(R.id.textView21);
        textView2=findViewById(R.id.textView26);
        textView=findViewById(R.id.textView31);
        textView3=findViewById(R.id.textView34);
        imageView=findViewById(R.id.imageView2);
        imageButton=findViewById(R.id.imageButton);
        final BlankFragment5 blankFragment5=new BlankFragment5();
        /*imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
             //   finish();
               // Intent intent=new Intent(setup.this,getClass());
                if(pictureBean.getPath()!=null) {
                 //   intent.putExtra("cut", pictureBean.isCut());
                    Bundle bundle=new Bundle();
                    bundle.putBoolean("cut",pictureBean.isCut());
                    bundle.putString("path",pictureBean.getPath());
                    bundle.putString("uri", String.valueOf(pictureBean.getUri()));
                    blankFragment5.setArguments(bundle);
                    getSupportFragmentManager().beginTransaction()
                            .replace(R.id.framelayout, blankFragment5).commit();
                   *//* intent.putExtra("path", pictureBean.getPath());
                    intent.putExtra("url", pictureBean.getUri());
                    Log.i("setup.this","TAG="+pictureBean.getPath());
                    startActivity(intent);*//*
                }else {
                    startActivity(intent);
                }
   */
    }
    public void onClickShowQMUIDialog(View view) {
        final QMUIDialog.EditTextDialogBuilder builder = new QMUIDialog.EditTextDialogBuilder(setup.this);
        builder.setTitle("昵称")
                .setPlaceholder("在此输入您的昵称")
                .setInputType(InputType.TYPE_CLASS_TEXT)
                .addAction("取消", new QMUIDialogAction.ActionListener() {
                    @Override
                    public void onClick(QMUIDialog dialog, int index) {
                        dialog.dismiss();
                    }
                })
                .addAction("确定", new QMUIDialogAction.ActionListener() {
                    @Override
                    public void onClick(QMUIDialog dialog, int index) {
                        CharSequence text = builder.getEditText().getText();
                        if (text != null && text.length() > 0) {
                            textView1.setText(text);
                            Toast.makeText(setup.this, "您的昵称: " + text, Toast.LENGTH_SHORT).show();
                            dialog.dismiss();
                        } else {
                            Toast.makeText(setup.this, "请填入昵称", Toast.LENGTH_SHORT).show();
                        }
                    }
                })
                .show();
    }

    public void onClickXueZe(View view){
        final String[] items = new String[]{"男", "女", "保密"};
        new QMUIDialog.MenuDialogBuilder(setup.this)
                .addItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(setup.this, "你选择了 " + items[which], Toast.LENGTH_SHORT).show();
                        textView2.setText(items[which]);
                        dialog.dismiss();
                    }
                })
                .show();
    }

    public void onClick(View v) {
        BasisTimesUtils.showDatePickerDialog(setup.this, BasisTimesUtils.THEME_HOLO_LIGHT, "请选择年月日", 2015, 1, 1, new BasisTimesUtils.OnDatePickerListener() {

            @Override
            public void onConfirm(int year, int month, int dayOfMonth) {
                String text=year + "-" + month + "-" + dayOfMonth;
                Toast.makeText(setup.this,text,Toast.LENGTH_LONG).show();
                String str3 = "<small>"+text+"</small>";
                textView.setText(Html.fromHtml(str3));
            }

            @Override
            public void onCancel() {
                Toast.makeText(setup.this,"cancel",Toast.LENGTH_LONG).show();
            }
        });
    }

    public void Weizhi(View v){
        JDCityPicker cityPicker = new JDCityPicker();
        JDCityConfig jdCityConfig = new JDCityConfig.Builder().build();

        jdCityConfig.setShowType(JDCityConfig.ShowType.PRO_CITY_DIS);
        cityPicker.init(this);
        cityPicker.setConfig(jdCityConfig);
        cityPicker.setOnCityItemClickListener(new OnCityItemClickListener() {
            @Override
            public void onSelected(ProvinceBean province, CityBean city, DistrictBean district) {
                textView3.setText(province.getName() + city.getName()+district.getName());
            }

            @Override
            public void onCancel() {
                Toast.makeText(setup.this,textView3.getText(),Toast.LENGTH_SHORT).show();
            }
        });
        cityPicker.showCityPicker();
    }

    public void paizhao(View v){
        PictureSelector
                .create(setup.this, PictureSelector.SELECT_REQUEST_CODE)
                .selectPicture(true);
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /*结果回调*/
        if (requestCode == PictureSelector.SELECT_REQUEST_CODE) {
            if (data != null) {
                pictureBean = data.getParcelableExtra(PictureSelector.PICTURE_RESULT);
                if (pictureBean.isCut()) {
                    imageView.setImageBitmap(BitmapFactory.decodeFile(pictureBean.getPath()));
                } else {
                    imageView.setImageURI(pictureBean.getUri());
                }

                //使用 Glide 加载图片
                /*Glide.with(this)
                        .load(pictureBean.isCut() ? pictureBean.getPath() : pictureBean.getUri())
                        .apply(RequestOptions.centerCropTransform()).into(mIvImage);*/
            }
        }
    }
}
